/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jobscheduling.gui;

import java.util.Iterator;
import java.util.List;
import jobscheduling.model.Solution;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 *
 * @author Dawid
 */
public class ComparingChart {
    public ComparingChart(List<Solution> solutions){
        XYSeriesCollection dataset = new XYSeriesCollection();

        JFreeChart chart = ChartFactory.createXYLineChart(
            "Compare solutions", "Iteration", "Target function",
            dataset, PlotOrientation.VERTICAL, true, false, false
        );
        Iterator<Solution> iterator = solutions.iterator();
        int i = 1;
        int maxX = 0;
        int bestKnown = 0;
        while(iterator.hasNext()){
            int X = 1;
            Solution next = iterator.next();
            XYSeries series = new XYSeries(i++ + ") " + next.toString());
            Iterator<Integer> iterator1 = next.getTimes().iterator();
            while(iterator1.hasNext()){
                Integer next1 = iterator1.next();
                series.add(X++, next1);
            }
            maxX = (X > maxX) ? X : maxX;
            bestKnown = next.getProblem().getBestSolution();
            dataset.addSeries(series);
        }
        
        /* draw signle best known solution line */
        XYSeries bestKnownSeries = new XYSeries("best known time");
        for (i = 0; i < maxX; ++i){
            bestKnownSeries.add(i, bestKnown);
        }

        dataset.addSeries(bestKnownSeries);
        
        ChartFrame frame1= new ChartFrame("Compare solutions",chart);
        frame1.setVisible(true);
        frame1.setSize(300,300);
    }
}
